package com.ktmall.service.impl;

import com.ktmall.mapper.WxUserMapper;
import com.ktmall.pojo.WxUser;
import com.ktmall.service.WxUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 微信用户相关Service实现类
 */
@Service
public class WxUserServiceImpl implements WxUserService {
    @Autowired
    private WxUserMapper wxUserMapper;
    @Override
    public WxUser findByOpenId(String openId) {

        return wxUserMapper.findByOpenId(openId);
    }

    @Override
    public int insert(WxUser user) {
        return wxUserMapper.insert(user);
    }

    @Override
    public int updateLastLoginTime(Integer id) {
        String lastLoginTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        WxUser user = new WxUser();
        user.setLastLoginTime(lastLoginTime);
        return wxUserMapper.updateLastLoginTime(id);
    }

    @Override
    public int updateWxUser(WxUser wxUser) {
        return wxUserMapper.updateWxUser(wxUser);
    }

    @Override
    public WxUser findById(Integer userId) {
        return wxUserMapper.findById(userId);
    }
}
